package com.xiehua.task.job.pool;


import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 说明:job
 *
 * @author Mr.zhang
 * @date 2018-03-31
 **/
public class Job implements Serializable {

    private static final long serialVersionUID = 1L;

    protected String topic;

    protected String jobId;//Job的唯一标识。用来检索和删除指定的Job信息。

    protected Long delay;//Job需要延迟的时间。单位：秒。（服务端会将其转换为绝对时间）

    protected String reqId = UUID.randomUUID().toString().replace("-", "");//每个任务注册到task_server时,对应一个请求id

    protected LocalDateTime createTime = LocalDateTime.now();//创建时间

    protected LocalDateTime updateTime;//修改时间

    protected JobType type;//任务类型

    protected JobStatus status;

    public Job() {
    }

    public enum JobStatus {
        delay,//不可执行状态，等待时钟周期。
        ready,//可执行状态，等待消费。
        notify,//任务已通知，但还未得到消费者的响应
        executeed,//客户端响应完成
        success,//任务执行成功
        fail;//执行失败
    }

    public enum JobType {
        delay,//延迟任务
        fixed;//定时任务
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }


    public Long getDelay() {
        return delay;
    }

    public void setDelay(Long delay) {
        this.delay = delay;
    }

    public String getReqId() {
        return reqId;
    }

    public void setReqId(String reqId) {
        this.reqId = reqId;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public JobType getType() {
        return type;
    }

    public void setType(JobType type) {
        this.type = type;
    }

    public JobStatus getStatus() {
        return status;
    }

    public void setStatus(JobStatus status) {
        this.status = status;
    }

    public String getJobId() {
        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    @Override
    public String toString() {
        return "Job{" +
                "topic='" + topic + '\'' +
                ", jobId='" + jobId + '\'' +
                ", delay=" + delay +
                ", reqId='" + reqId + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", type=" + type +
                ", status=" + status +
                '}';
    }

    public static class Query {

        private String topic;

        protected String jobId;//Job的唯一标识。用来检索和删除指定的Job信息。

        protected String reqId;//每个任务注册到task_server时,对应一个请求id

        protected LocalDateTime startTime;//创建时间

        protected LocalDateTime endTime;//修改时间

        protected JobType type;//任务类型

        protected JobStatus status;

        private int page = 0;

        private int pageSize = 10;

        public String getTopic() {
            return topic;
        }

        public void setTopic(String topic) {
            this.topic = topic;
        }

        public String getJobId() {
            return jobId;
        }

        public void setJobId(String jobId) {
            this.jobId = jobId;
        }

        public String getReqId() {
            return reqId;
        }

        public void setReqId(String reqId) {
            this.reqId = reqId;
        }

        public LocalDateTime getStartTime() {
            return startTime;
        }

        public void setStartTime(LocalDateTime startTime) {
            this.startTime = startTime;
        }

        public LocalDateTime getEndTime() {
            return endTime;
        }

        public void setEndTime(LocalDateTime endTime) {
            this.endTime = endTime;
        }

        public JobType getType() {
            return type;
        }

        public void setType(JobType type) {
            this.type = type;
        }

        public JobStatus getStatus() {
            return status;
        }

        public void setStatus(JobStatus status) {
            this.status = status;
        }

        public int getPage() {
            return page;
        }

        public void setPage(int page) {
            this.page = page;
        }

        public int getPageSize() {
            return pageSize;
        }

        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
        }

        @Override
        public String toString() {
            return "Query{" +
                    "topic='" + topic + '\'' +
                    ", jobId='" + jobId + '\'' +
                    ", reqId='" + reqId + '\'' +
                    ", startTime=" + startTime +
                    ", endTime=" + endTime +
                    ", type=" + type +
                    ", status=" + status +
                    ", page=" + page +
                    ", pageSize=" + pageSize +
                    '}';
        }
    }

    public static class JobPage {

        private int totalPage;

        private int totalRows;

        private int pageSize = 10;

        private int currentPage;

        private List<Job> list = new ArrayList<>();

        public int getTotalPage() {
            return totalPage;
        }

        public void setTotalPage(int totalPage) {
            this.totalPage = totalPage;
        }

        public int getTotalRows() {
            return totalRows;
        }

        public void setTotalRows(int totalRows) {
            this.totalRows = totalRows;
        }

        public int getPageSize() {
            return pageSize;
        }

        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
        }

        public int getCurrentPage() {
            return currentPage;
        }

        public void setCurrentPage(int currentPage) {
            this.currentPage = currentPage;
        }

        public List<Job> getList() {
            return list;
        }

        public void setList(List<Job> list) {
            this.list = list;
        }
    }
}
